home *** CD-ROM | disk | FTP | other *** search
/ Ian & Stuart's Australian Mac 1 / Ian and Stuart's One (Australia).iso / Australasian Legends / Commercial / Rainbow Hill / MacDOS™ 2.0.0 / batches / delPath.bat < prev    next >
DOS Batch File  |  1994-08-26  |  2KB  |  78 lines

  1. @echo off
  2. !  delPath.bat    Batch file to remove a folder from the PATH
  3. !
  4. !  delPath pos
  5. !
  6. !  'pos' is the position within the PATH of the folder to be removed. If
  7. !        'pos' is omitted or exceeds the number of folders in the path,
  8. !        the last folder is removed.
  9. !
  10. !  Example:
  11. !    delPath applied to the initial PATH "first;second;third" will have the
  12. !    following results:
  13. !        delPath                    first;second
  14. !        delPath 1                second;third
  15. !        delPath 2                first;third
  16. !        delPath 3                first;second
  17. !        delPath 4                first;second;third
  18. !
  19. !  Copyright © 1994 by Rainbow Hill Pty Ltd. All rights reserved.
  20. !
  21.  
  22.     set delPath_saved_path=%PATH%
  23.     set doserr=0
  24.  
  25.     ! determine the position
  26.     if "%1 " == " " goto FROM_END_LBL
  27.     set delPath_pos=%1
  28.     if "%1" == 1 goto FROM_START_LBL
  29.  
  30.     !
  31.     ! scan the existing PATH and skip one folder at a time until you reach
  32.     ! the requested position or until you run out of folders
  33.     !
  34.     set delPath_tail=%PATH%
  35. :SKIP_ONE_LBL
  36.     if %delPath_pos% == 0 goto POS_FOUND_LBL
  37.     if "%delPath_tail%" == %%delPath_TAIL%% goto FROM_END_LBL
  38.     sstr delPath_tail ; /R
  39.     if %doserr% == 72 goto FROM_END_LBL
  40.     decr delPath_pos
  41.     goto SKIP_ONE_LBL
  42.  
  43. :FROM_END_LBL
  44.     !
  45.     ! remove the last folder (if any)
  46.     if "%PATH% " == " " goto DONE_LBL
  47.     set doserr=0
  48.     sstr path ; /E/L
  49.     if %doserr% == 72 set path=
  50.     goto DONE_LBL
  51.  
  52. :FROM_START_LBL
  53.     !
  54.     ! remove the first folder (if any)
  55.     if "%PATH% " == " " goto DONE_LBL
  56.     sstr path ; /R
  57.     if %doserr% == 72 set path=
  58.     goto DONE_LBL
  59.  
  60. :POS_FOUND_LBL
  61.     !
  62.     ! remove the requested folder (cannot be the first or the last one)
  63.     decr path by "%delPath_tail%"
  64.     decr path by 1
  65.     sstr path ; /E/L
  66.     incr path by ";%delPath_tail%"
  67.     goto DONE_LBL
  68.  
  69. :ERR_LBL
  70.     show %doserr%
  71.     set path=%delPath_saved_path%
  72.  
  73. :DONE_LBL
  74.     ! remove the global variables
  75.     set delPath_pos=
  76.     set delPath_tail=
  77.     set delPath_saved_path=
  78.